package com.lb.bs.client.adapter.spring;

import com.lb.bs.client.repository.BeanHolder;
import org.springframework.beans.factory.FactoryBean;

/**
 * program: LB-BS-Client
 * author: bsworld.xie
 * create: 2020-05-18 20:44
 * description:
 */
public class SpringFactoryBean<T> implements FactoryBean<T> {

    Object originBean;


    @Override
    public T getObject() throws Exception {
        Object proxyBean = BeanHolder.getHolder().getProxyBeanByOriginClazzType(originBean.getClass());
        return (T) proxyBean;
    }

    @Override
    public Class<?> getObjectType() {
        return BeanHolder.getHolder().getProxyBeanByOriginClazzType(originBean.getClass()).getClass();
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    public SpringFactoryBean(Object originBean) {
        this.originBean = originBean;
    }
}
